package com.csc.dao;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Repository;

import com.csc.domain.User;

@Repository
public class UserDaoImpl implements UserDao {

	@PersistenceContext
	private EntityManager em;

	static final Logger logger = Logger.getLogger(UserDaoImpl.class);

	// ThanhBinh
	public List<User> getAllUsers() {

		logger.info("Go getAllUsers");

		TypedQuery<User> query = em.createQuery("SELECT user FROM User user ", User.class);
		return query.getResultList();
	}

	// TrangNguyen
	public User getUserById(int userId) {
		
		logger.info("Get User Id = " + userId);

		return em.find(User.class, userId);
	}

}
